﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Diagnostics;
namespace FinosServiceLibrary.Server {
    public enum LogLevel { error,warning,trace }
    public class Logger {
        public static LogLevel level = LogLevel.trace;
        private static string logFilePath { get { return AppDomain.CurrentDomain.SetupInformation.ApplicationBase + DateTime.Today + ".txt"; } }
        public static void error(string msg) {
            log(msg, LogLevel.error);
        }
        public static void warning(string msg) {
            log(msg, LogLevel.warning);
        }
        public static void trace(string msg) {
            log(msg, LogLevel.trace);
        }
        public static void log(string msg,LogLevel l) {
            msg = "[" + DateTime.Now.ToLocalTime() + "]" + msg;
            if (level >= l) {
                Console.WriteLine(msg);
            }
            AdminClient.TraceMessage(msg);
            if (level < LogLevel.trace) {
                File.AppendAllText(logFilePath, msg + "\n");
            }
        }
    }
    public static class LoggerException {
        public static void LoggerE(this Exception e) {
            while (e.InnerException != null) 
                e = e.InnerException;
            Logger.error(e.GetType().Name+":"+e.Message);
        }
    }
}
